home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / emerald / emrldsys.lha / Kernel / FileLoad / readDoto.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-17  |  1.5 KB  |  63 lines

  1.  
  2. /*  C O P Y R I G H T   N O T I C E :                                     */
  3. /* Copyright 1986 Eric Jul and Norm Hutchinson.     May not be used for any  */
  4. /* purpose without written permission from the authors.              */
  5.  
  6. #include <stdio.h>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <sys/file.h>
  10. #include <a.out.h>
  11.  
  12. #include "Kernel/h/stdTypes.h"
  13. #include "Kernel/h/system.h"
  14. #include "Kernel/h/assert.h"
  15. #include "Kernel/h/ecTypes.h"
  16. #include "Kernel/h/emTypes.h"
  17. #include "Kernel/h/map.h"
  18.  
  19. extern ODTag    stdDotoODTag;
  20. #ifndef NODISK
  21. extern char nodisk;
  22. #endif
  23.  
  24. static Map dotomap = NULL;
  25.  
  26. DotoFilePtr readDotoFile(filename)
  27. char *filename;
  28. {
  29.   DotoFilePtr dotoptr;
  30.   int inf;
  31.   struct stat statbuf;
  32.   ODTag *ptr;
  33.  
  34. #ifndef NODISK
  35.   if(nodisk) {
  36. #endif
  37.     return NULL;
  38. #ifndef NODISK
  39.   } else {
  40.     if (!dotomap) dotomap = Map_Create();
  41.     inf = open(filename, O_RDONLY, 0);
  42.     if (inf == NULL) return NULL;
  43.     if (fstat(inf, &statbuf) != 0) return NULL;
  44.     dotoptr = (DotoFilePtr) emalloc((int)(statbuf.st_size+sizeof(ODTag)));
  45.     Map_Insert(dotomap, (int) dotoptr, (int) dotoptr);
  46.     ptr = (ODTag *) dotoptr;
  47.     *ptr = stdDotoODTag;
  48.     dotoptr = (DotoFilePtr) (ptr+1);
  49.     if (read(inf, (char *) dotoptr, (int)statbuf.st_size) != statbuf.st_size) {
  50.       (void) close(inf);
  51.       emfree((char *)ptr);
  52.       return NULL;
  53.     }
  54.     (void) close(inf);
  55.     if (!isOkDoto(dotoptr)) {
  56.       emfree((char *)ptr);
  57.       return NULL;
  58.     }
  59.     return(dotoptr);
  60.   }
  61. #endif NODISK
  62. }
  63.